package com.isman.domain;


import java.io.Serializable;

import javax.persistence.*;

import com.google.appengine.repackaged.org.codehaus.jackson.annotate.JsonBackReference;
import com.google.appengine.repackaged.org.codehaus.jackson.annotate.JsonIgnore;
import com.google.appengine.repackaged.org.codehaus.jackson.annotate.JsonManagedReference;
import com.google.appengine.repackaged.org.codehaus.jackson.map.annotate.JsonSerialize;

import java.util.Set;

@Entity
@Table(name="department")
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Department implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(unique=true, nullable=false)
	private int id;

	@Column(nullable=false, length=32)
	private String name;

	@JsonManagedReference
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id")
	private Department parent;

	@JsonBackReference
	@JsonIgnore
	@OneToMany(mappedBy="parent")
	private Set<Department> departments;
	
	@JsonBackReference
	@JsonIgnore
	@OneToMany(mappedBy="department",fetch=FetchType.LAZY)
	private Set<Person> persons;

	public Department() {
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Department getParent() {
		return parent;
	}

	public void setParent(Department parent) {
		this.parent = parent;
	}

	public Set<Department> getDepartments() {
		return departments;
	}

	public void setDepartments(Set<Department> departments) {
		this.departments = departments;
	}

	public Set<Person> getPersons() {
		return persons;
	}

	public void setPersons(Set<Person> persons) {
		this.persons = persons;
	}
}